﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Apache.NMS;
using Apache.NMS.Util;
using Apache.NMS.ActiveMQ;
using Apache.NMS.ActiveMQ.Commands;

namespace ConsoleApplication1
{

    class Subscriber
    {
        public const String QUEUE_ADVISORY_DESTINATION = "ActiveMQ.Advisory.Queue";
        static void Main(string[] args)
        {
            //Create the Connection factory 
            Uri uri = new Uri("tcp://localhost:8161/");
            IConnectionFactory factory = new
               ConnectionFactory(uri);
            //Create the connection 
            using (IConnection connection =
               factory.CreateConnection())
            {
                connection.ClientId = "testing listener";
                connection.Start();

                //Create the Session 
                using (ISession session = connection.CreateSession())
                {
                    //Create the Consumer 
                    IDestination d = session.GetQueue(QUEUE_ADVISORY_DESTINATION);
                    IMessageConsumer consumer = session.CreateConsumer(d); 
                    consumer.Listener += new MessageListener(
                       consumer_Listener);
                    Console.ReadLine();
                }
            }
        }
        static void consumer_Listener(IMessage message)
        {
            Console.WriteLine("Receive: " +
               ((ITextMessage)message).Text);
        }

    }
}
